package com.drojian.review;

import android.app.Activity;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

public class MainActivity extends Activity {
    private RelativeLayout.LayoutParams layout;
    private String TAG = "xjq";
    private TextView tv1;
    private Button btn1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG, "onCreate: ");
        tv1 = findViewById(R.id.tv1);
        btn1 = findViewById(R.id.btn1);
        if (savedInstanceState != null) {
            // 从Bundle中恢复User1对象
            User1 user = savedInstanceState.getParcelable("user_key");
            if (user != null) {
                // 这里假设你有方法来根据User1对象更新UI，例如设置到TextView中
                btn1.setText("姓名："+user.getName()+"年龄为："+user.getAge());
            }
        } else {
            // 第一次创建时初始化数据
            User1 user = new User1();
            user.setName("张三");
            user.setAge(18);
            btn1.setText("姓名："+user.getName()+"年龄为："+user.getAge());
            btn1.setAllCaps(false);
            tv1.setBackgroundColor(getColor(R.color.black));
            setLayout();
        }
    }
    private void setLayout() {
        layout = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100);
        layout.addRule(RelativeLayout.ALIGN_PARENT_START);
        layout.addRule(RelativeLayout.CENTER_VERTICAL);
        tv1.setLayoutParams(layout);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart: ");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume: ");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG, "onPause: ");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG, "onStop: ");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy: ");
    }

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState, @NonNull PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        User1 user2 = new User1();
        user2.setName("张三");
        user2.setAge(18);
        // 为了将User1对象保存到Bundle中，User1类需要实现Parcelable或Serializable接口
        // 假设User1实现了Parcelable
        outState.putParcelable("user_key", user2);
    }


}